
var requestUrl = "/xinlu/hljssc/hljsscAction.html"
var jzsj,now;
var inter;
var zxhzVal = "1,3,6,10,15,21,28,36,45,55,63,69,73,75,75,73,69,63,55,45,36,28,21,15,10,6,3,1";
var zhuxuanhezhiVal2 = "0,1,2,2,4,5,6,8,10,11,13,14,14,15,15,14,14,13,11,10,8,6,5,4,2,2,1,0";

$(function(){
	
	//regFunction();
	loadWfPage();
	regKjxxLaster();
	getJrtzList();
	getCqsscEndNow();
	
	
	function loadWfPage(){
		
		var pageVal = $("input[name='wflx']:checked").val();
		$("#wfXunhao").load('wf/'+ pageVal +'.jsp',"",regFunction);
		
		//	初始化
		$("#jrkj").attr("class", "Slider01");
		$("#jrtz").attr("class", "Slider02");
		$("#nagvior1 tr:nth-child(2)").css("display", "none");
		$("#jrtzTable").css("dispaly", "none");
		$("#nagvior1 tr:nth-child(1)").css("display", "");
		$("#zjxxTable").css("display", "");
	}
	
	//	计算剩余投注时间
	function getCqsscEndNow(){
		
		var now = new Date();
		var hasDataFlag = false;
		$.ajax({
			url : requestUrl,
			type : "post",
			async : false,
			cache : false,
			dataType : "json",
			data : {
				pageId : "hljssc",
				doAction : "getCqsscEndNow"
			},
			error : function(){
			
				alert('网络发生异常,请重试.....');
			},
			success : function(data){
				if(data == null){
					$("#nowTime").text("00:00:00");
					clearInterval(inter);
					setTimeout(getCqsscEndNow,10000);
					hasDataFlag = true;
				}else{
					
					var nowtime = data.nowtime;
					var jssjstr = data.qsjzsj;
					now = new Date(nowtime.substring(0,4), parseInt(nowtime.substring(4,6)) - 1, nowtime.substring(6,8), nowtime.substring(8,10), nowtime.substring(10,12), nowtime.substring(12,14), 0);
					jzsj = new Date(jssjstr.substring(0,4), parseInt(jssjstr.substring(4,6)) - 1, jssjstr.substring(6,8), jssjstr.substring(9,11), jssjstr.substring(12,14), jssjstr.substring(15,17), 0);
					
					var date3 = jzsj.getTime() - now.getTime();
					
					var leave1=date3%(24*3600*1000)    //计算天数后剩余的毫秒数
					var hours=Math.floor(leave1/(3600*1000));
					
					//计算相差分钟数
					var leave2=leave1%(3600*1000)        //计算小时数后剩余的毫秒数
					var minutes=Math.floor(leave2/(60*1000));
					 
					
					//计算相差秒数
					var leave3=leave2%(60*1000)      //计算分钟数后剩余的毫秒数
					var seconds=Math.round(leave3/1000);
					
					
					$("#nowIssue").text(data.qs);
					$("#nowTime").text((hours >= 10 ? hours : "0" + hours) + ":" + (minutes >= 10 ? minutes : "0" + minutes) + ":" + (seconds >= 10 ? seconds : "0" + seconds));
					$("#addtime").text(data.dgjssj);					
					$("#nowdatenumers").text(data.qh);
				}
				
			}
		});
		
		if(!hasDataFlag){
			
			inter = setInterval(refershTime,1000);
		}else{
			
			return;
		}
	}
	
	//	刷新时间
	function refershTime(){
		
		var now = new Date();
		
		if(jzsj.getTime() > now.getTime()){
			
			var date3 = jzsj.getTime() - now.getTime();
					
			var leave1=date3%(24*3600*1000)    //计算天数后剩余的毫秒数
			var hours=Math.floor(leave1/(3600*1000));
			
			//计算相差分钟数
			var leave2=leave1%(3600*1000)        //计算小时数后剩余的毫秒数
			var minutes=Math.floor(leave2/(60*1000));
			 
			
			//计算相差秒数
			var leave3=leave2%(60*1000)      //计算分钟数后剩余的毫秒数
			var seconds=Math.round(leave3/1000);
			
			if(hours == 0 && minutes == 0 && seconds <= 30){
				$("#nowTime").text("00:00:00");
			}else{
				
				$("#nowTime").text((hours >= 10 ? hours : "0" + hours) + ":" + (minutes >= 10 ? minutes : "0" + minutes) + ":" + (seconds >= 10 ? seconds : "0" + seconds));
			}
			
		}else{
			
			window.clearInterval(inter);
			getCqsscEndNow();
		}
		
	
	}
	
	//	玩法修改的时候，改变页面
	$("input[name='wflx']").bind("click", function(){
		
		var pageVal = $("input[name='wflx']:checked").val();
		$("#wfXunhao").load('wf/'+ pageVal +'.jsp',"",regFunction);
		
	});
	
	//	切换时，重新注册事件
	function regFunction(){
		
		//	号码选中切换
		$.each($("li.btn_black"), function(i, item){

			$(item).toggle(function(){
				$(this).attr("class", "btn_red");
			}, function(){
				$(this).attr("class", "btn_black");
			});
		
			
		});
		
		
		$(".shuaixuancaidan dd:nth-child(1)").bind("click", function(){
		
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_red");
			});
		});
		
		$(".shuaixuancaidan dd:nth-child(2)").bind("click", function(){
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_black");
			});
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li:even"), function(i, item){
				
				$(this).attr("class", "btn_red");
			});
		});
		
		$(".shuaixuancaidan dd:nth-child(3)").bind("click", function(){
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_black");
			});
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li:odd"), function(i, item){
				
				$(this).attr("class", "btn_red");
			});
		});
		
		$(".shuaixuancaidan dd:nth-child(4)").bind("click", function(){
		
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_red");
			});
		});
		
		$(".shuaixuancaidan dd:nth-child(5)").bind("click", function(){
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_black");
			});
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li:even"), function(i, item){
				
				$(this).attr("class", "btn_red");
			});
		});
		
		$(".shuaixuancaidan dd:nth-child(6)").bind("click", function(){
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_black");
			});
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li:odd"), function(i, item){
				
				$(this).attr("class", "btn_red");
			});
		});
		
		$(".shuaixuancaidan dd:nth-child(7)").bind("click", function(){
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_black");
			});
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li:gt(4)"), function(i, item){
				
				$(this).attr("class", "btn_red");
			});
		});
		
		$(".shuaixuancaidan dd:nth-child(8)").bind("click", function(){
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_black");
			});
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li:lt(4)"), function(i, item){
				
				$(this).attr("class", "btn_red");
			});
		});
		
		
		$(".shuaixuancaidan dd:nth-child(9)").bind("click", function(){
			
			$.each($(this).parent().parent().parent().parent().parent().parent().children("li"), function(i, item){
				
				$(this).attr("class", "btn_black");
			});
		});
		
		
		
		//	选号提交
		$("#xuanhaosubmit").bind("click", function(){
			
			var numLength = $("#mainm_ml2l .top").length;
			
			var select_num = '';
			var mark1 = 1;
			var numLengtMark = 0;
			
			//	玩法类型
			var wflxName = $("input[name='wflx']:checked").val();
			
			//	复式
			if(numLength > 0){
				
				$.each($("#mainm_ml2l .top"), function(index, item){
					var m2 = 1;
					$.each($(item).find(".btn_red"), function(i, item){
						
						if(wflxName != 'HLJSSC_QSHZ' && wflxName != 'HLJSSC_HSHZ' && wflxName != 'HLJSSC_HSZH' && wflxName != 'HLJSSC_QSZH'){
							select_num += $.trim($(this).text());
						}else{
							
							select_num += $.trim($(this).text()) + ",";
						}
						
						if(wflxName == 'HLJSSC_DWD'){
							mark1++;
						}else{
							m2 = (i + 1);
						}
						
						if(i == 0){
							numLengtMark++;
						}
					});
					
					if(wflxName != 'HLJSSC_DWD'){
						
						mark1 *= m2;
					}
					select_num += ',';
				});
			}else{
				
				if(wflxName == 'HLJSSC_HSZXDS' || wflxName == 'HLJSSC_QSZXDS'){
					dealKeywordInput(3, true, false);
					
					return;
				}else if(wflxName == 'HLJSSC_QEDS' || wflxName == 'HLJSSC_HEDS'){
					
					dealKeywordInput(2, true, false);
					
					return;
				}else if(wflxName == 'HLJSSC_HSZX' || wflxName == 'HLJSSC_QSZX'){
					
					dealKeywordInput(3, true, true);
					
					return;
				}
				
				
			}
			
			if(wflxName != 'HLJSSC_DWD' && wflxName != 'HLJSSC_HSZS' && wflxName != 'HLJSSC_QSZS'){
				
				//	号码未选择完全
				if(numLengtMark < numLength){
					
					alert('选号不完整,请检查输入!');
					
					return;
				}
			}else if(wflxName == 'HLJSSC_HSZS' || wflxName == 'HLJSSC_QSZS'){
				
				if(mark1 < 2){
					
					alert('选号不完整,请检查输入!');
					return;
				}
				
				mark1 = mark1 * (mark1 - 1);
			}else{
				
				mark1 -= 1;
			}
			
			$.each($("#mainm_ml2l .top .btn_red"),function(index, item){
				
				$(item).attr("class", "btn_black");
			});
			
			select_num = select_num.substring(0,select_num.length - 1);
			
			if(wflxName == 'HLJSSC_HSHZ' || wflxName == 'HLJSSC_QSHZ'){
				var select_num_other = "";
				mark1 = 0;
				var arr = zxhzVal.split(",");
				select_num = select_num.substring(0,select_num.length - 1);
				var arr2 = select_num.split(",");
				for(var k = 0; k < arr2.length; k++){
					mark1 += parseInt(arr[parseInt(arr2[k])]);
					
				}
			}else if(wflxName == "HLJSSC_QSZH" || wflxName == "HLJSSC_HSZH"){
				
				var select_num_other = "";
				mark1 = 0;
				var arr = zhuxuanhezhiVal2.split(",");
				select_num = select_num.substring(0,select_num.length - 1);
				var arr2 = select_num.split(",");
				for(var k = 0; k < arr2.length; k++){
					
					//select_num_other += select_num.substring(0,k+1) + ",";
					mark1 += parseInt(arr[parseInt(arr2[k])]);
					
				}
			}else if(wflxName == 'HLJSSC_QSBDW' || wflxName == 'HLJSSC_HSBDW'){
				
				mark1 = select_num.length;
			}
				
			var zhushu = mark1;
			
			if(wflxName == 'HLJSSC_HSZL' || wflxName == 'HLJSSC_QSZL'){
				
				if(select_num.length < 3){
					
					alert('数据不完整，请重新输入！');
					return;
				}
				
				var num = select_num.length - 3;
				
				zhushu = 1;
				var markNum = 0;
				//	alert(num);
				for(var i = num; i > 0; i--){
					
					zhushu *= (select_num.length-markNum)/i;
					markNum++;
				}
			}else if(wflxName == 'HLJSSC_HEZE'){
				
				if(select_num.length < 2 || select_num.length > 7){
					
					alert('数据错误，输入的个数2-7之间！');
					return;
				}
				
				var num = select_num.length - 2;
				
				zhushu = 1;
				var markNum = 0;
				//	alert(num);
				for(var i = num; i > 0; i--){
					
					zhushu *= (select_num.length-markNum)/i;
					markNum++;
				}
			}
			
			var wflxName = $("input[name='wflx']:checked").parent().text();
			
			var xuhao = 0;
			$.each($("#mainm_ml2r ul"), function(i, item){
				
				xuhao = i + 1;
			});
			var selectedVal = "<ul><li class='li1'>"+ (xuhao +1) +"、" + wflxName + "</li><li class='li2'>"+ select_num +"</li><li class='li3'>"+ zhushu +"注</li><li class='li4'>￥" + ForDight(zhushu * parseFloat("2.00") * parseFloat($("#btxishudhid .color").attr("yjfVal")),2) + "</li><li  class='x'>×</li></ul>";
			
			$(selectedVal).appendTo("#mainm_ml2r");
			//$(".mutlp_input").val(parseInt($(".mutlp_input").val()) + zhushu);
			$("#danbeizongzhushu").text(parseInt($("#danbeizongzhushu").text()) + zhushu);
			$("#danbeizongjine").text(ForDight(parseFloat($("#danbeizongjine").text()) + zhushu * parseFloat($("#multiples").val()) *  parseFloat("2.00")  * parseFloat($("#btxishudhid .color").attr("yjfVal")), 2));
			//	$("#danbeizongjine").text(parseFloat($("#danbeizongjine").text()) + zhushu *  parseFloat("2.00"));
			
			//var codesVal = $("#codes").val();
			//if(codesVal != ''){
				
				//$("#codes").val(codesVal + "$" + select_num);
			//}else{
				
				//$("#codes").val(codesVal + select_num);
			//}
			
			//$("#onemoney").val($("#danbeizongjine").text());
			//$("#allmoney").val(parseFloat($("#onemoney").val()) * parseInt($(".mutlp_input").val()));
			//$("#beishu").val($(".mutlp_input").val());
			
			
			$("#mainm_ml2r ul:nth-child("+(xuhao +1)+")").find(".x").bind("click", function(){
				
				var zongjiner = $(this).parent().children(".li4").text();
				var dazhushu = $(this).parent().children(".li3").text(); 
				
				$("#danbeizongzhushu").text(parseInt($("#danbeizongzhushu").text()) - parseInt(dazhushu.substring(0, dazhushu.length - 1)));
				$("#danbeizongjine").text(ForDight( parseFloat($("#danbeizongjine").text()) - parseInt($("#multiples").val()) * parseFloat(zongjiner.substring(1, zongjiner.length)), 2));
				
				
				$.each($(this).parent().nextAll(), function(i, item){
					var li1 = $(item).children(".li1").text();
					$(item).children(".li1").text(parseInt(li1.substring(0, li1.indexOf("、"))) - 1 + li1.substring(li1.indexOf("、"), li1.length));
				});
				
				$(this).parent().remove();
			});
			
				
		});
		
		//	清空统计值
		clearOtherTotalValue();
		
		changeYJF();
	}

	//	修改圆角分
	function changeYJF(){
		
		$("#btxishudhid li").bind("click", function(){
			
			var oldMs = parseFloat($("#btxishudhid .color").attr("yjfVal"));
			$("#btxishudhid .color").attr("class", "");
			
			$(this).attr("class", "color");
			//	设置选号的投注模式
			$("#dqbtxszhi").text($(this).text() + "模式");
			
			var newVal = parseFloat($(this).attr("yjfVal"));
			
			var changeRate = newVal/oldMs;
			var noCheckFlag = true;
			
			$.each($("#mainm_ml2r ul"),function(i, item){
				if(i == 0){
					noCheckFlag = false;
				}
				
				var danzhujiner = $(item).find("li:nth-child(4)").text() + "";
				$(item).find("li:nth-child(4)").text("￥" + ForDight(parseFloat(danzhujiner.substring(1, danzhujiner.length)) * changeRate,2));
			});
			
			if(!noCheckFlag){
				
				$("#danbeizongjine").text(ForDight(parseFloat($("#danbeizongjine").text()) * changeRate, 2));
			}
			
			//$("#yues").text(parseFloat($("#yues").text()) * changeRate * 1);
		});
	}
	
	function dealKeywordInput(length, canRepeat, isFix){
		
		var codes = $("#inputcodes").val();
		
		codes = codes.replace(/\n/g, "" ); 
		
		if(codes == ''){
			
			alert('请输入号码!');
			return false;
		}
		
		if(!checkDsInput(codes,length)){
			
			alert('输入的号码含有非法字符,请确认输入!');
			return false;
		}
		
		codes = codes.replace(/[\s]{1,}/g, ";" );
		codes = codes.replace(/[,]{1,}/g, ";" );
		
		var codesVal;
		
		if(codes.indexOf(";") != -1){
			
			codesVal = codes.split(";");
		}else if(codes.indexOf(" ") != -1){
			
			codesVal = codes.split(" ");
		}else if(codes.indexOf(",") != -1){
			
			codesVal = codes.split(",");
		}else{
			
			codesVal = codes.split("$");
		}
		
		var outLengthFlag = false;
		var lessLengthFlag = false;
		var hasRepeat = false;
		var markVal = "";
		for(var i = 0; i < codesVal.length; i++){
			
			if(codesVal[i] != ''){
				
				if((codesVal[i]).length > length){
					
					outLengthFlag = true;
				}
				
				if((codesVal[i]).length < length){
					
					lessLengthFlag = true;
				}
				
				if(!canRepeat){
					
					for(var j = 0; j < (codesVal[i]).length; j++){
						
						if((codesVal[i]).indexof((codesVal[i]).substring(j, j+1))){
							hasRepeat = true;
						}
					}
				}
				
				if(lessLengthFlag){
					alert("选号[" + codesVal[i] + "]长度小于" + length);
					return false;
				}
				
				if(outLengthFlag){
					
					alert("选号[" + codesVal[i] + "]长度超过" + length);
					return false;
				}
				
				if(hasRepeat){
					alert("选号[" + codesVal[i] + "]不允许重复的数字");
				}
				
				if(isFix){
					if((codesVal[i].substring(0, 1)== codesVal[i].substring(1, 2)) && (codesVal[i].substring(0, 1)== codesVal[i].substring(2, 3))&&(codesVal[i].substring(1, 2)== codesVal[i].substring(2, 3))){
						
						alert("选号[" + codesVal[i] + "]只能有两个重复!");
						return false;
					}
					
				}
			}
		}
		
		
		var zhushu = codesVal.length;
		var wflxName = $("input[name='wflx']:checked").parent().text();
		
		var xuhao = 0;
		$.each($("#mainm_ml2r ul"), function(i, item){
			
			xuhao = i + 1;
		});
		
		for(var i = 0; i < codesVal.length; i++){
			if(codesVal[i] != ''){
				var selectedVal = "<ul><li class='li1'>"+ (xuhao + i + 1) +"、" + wflxName + "</li><li class='li2'>"+ codesVal[i] +"</li><li class='li3'>"+ 1 +"注</li><li class='li4'>￥" +  ForDight(parseFloat("2.00") * parseFloat($("#btxishudhid .color").attr("yjfVal")),2) + "</li><li  class='x'>×</li></ul>";
				$(selectedVal).appendTo("#mainm_ml2r");
			}
		}
		
		$("#danbeizongzhushu").text(parseInt($("#danbeizongzhushu").text()) + zhushu);
		$("#danbeizongjine").text(ForDight(parseFloat($("#danbeizongjine").text()) + zhushu * parseInt($("#multiples").val()) *  parseFloat("2.00") * parseFloat($("#btxishudhid .color").attr("yjfVal"))),2);
		
		$("#inputcodes").val('');
		
		$("#mainm_ml2r ul:nth-child("+(xuhao +1)+")").find(".x").bind("click", function(){
				
				var zongjiner = $(this).parent().children(".li4").text();
				var dazhushu = $(this).parent().children(".li3").text(); 
				
				$("#danbeizongzhushu").text(parseInt($("#danbeizongzhushu").text()) - parseInt(dazhushu.substring(0, dazhushu.length - 1)));
				$("#danbeizongjine").text(ForDight( parseFloat($("#danbeizongjine").text()) - parseInt($("#multiples").val()) * parseFloat(zongjiner.substring(1, zongjiner.length)), 2));
				
				
				$.each($(this).parent().nextAll(), function(i, item){
					var li1 = $(item).children(".li1").text();
					$(item).children(".li1").text(parseInt(li1.substring(0, li1.indexOf("、"))) - 1 + li1.substring(li1.indexOf("、"), li1.length));
				});
				
				$(this).parent().remove();
			});
	}
	
	
	//	重置统计值
	function clearOtherTotalValue(){
		
		//	重置隐藏信息
		document.tzForm.reset();
		
		$("#multiples").val("1");
		$("#danbeizongzhushu").text("0");
		$("#danbeizongjine").text("0.00");
		$("#mainm_ml2r").html("");
	}
	
	//	清空选号
	$("#cleartzx").bind("click", function(){
		
		$("#mainm_ml2r").html('');
		$("#danbeizongzhushu").text("0");
		$("#danbeizongjine").text("0.00");
		//	重置隐藏信息
		document.tzForm.reset();
	});
	
	//	根据大 的玩法类型获取小的玩法类型
	$("#main_ml1top li").bind("click", function(){
		
		$.each($("#main_ml1top li"),function(i, item){
			
			$(item).attr("class", "hcu");
		});
		
		$(this).attr("class", "libg hcu1");
		
		$.each($("#main_gamenr ul"),function(i, item){
				
			$(item).css("display","none");
		});
		
		
		
		$("#game" + $(this).attr("value")).css("display","block");
		
		$("#game" + $(this).attr("value") + " li:nth-child(1) input[type='radio']").attr("checked", "checked");
		loadWfPage();
	});
	
	
	//	确认投注提交
	$("#betting_enter").bind("click", function(){
		
		if($("#nowTime").text() == "00:00:00"){
			
			alert('本期已过销售期,请等待下一期的投注!');
			
			return false;
		}
		
		if(parseInt($("#multiples").val()) == 0){
			
			alert('倍数至少为1倍,请重新输入');
			$("#multiples").focus();
			return;
		}
		
		$("#expect").val($("#nowdatenumers").text());
		
		//	设置隐藏值
		setFormData();
		
		if($.trim($("#codes").val()) == ''){
			alert('请选择投注号码后再进行投注!');
			return false;
		}
		
		if(checkFormData()){
			var message = "您确认要投注？\r\n";
//			var cods = $("#codes").val().split("$");
//			
//			for(var i = 0; i < cods.length; i++){
//				
//				message += cods[i] + "\r\n";
//			}
			
			message += "需支付￥" + $("#allmoney").val() + "\r\n";
				
			message += "追加" + $("#expect").val() + "期？";
			
			
			$("#xl").val($("#shop_right select option:selected").val());
			//$("#yjf").val($("#btxishudhid .color").text());
			
			if(confirm(message)){
				
				$.ajax({
					
					url : "/xinlu/hljssc/hljsscAction.html",
					type : "post",
					data : {
						pageId : "hljssc",
						doAction : "addTzjlInfo",
						codes : $("#codes").val(),
						allmoney : $("#allmoney").val(),
						onemoney : $("#onemoney").val(),
						protype : $("#protype").val(),
						beishu : $("#beishu").val(),
						expect : $("#expect").val(),
						xl : $("#xl").val(),
						yjf : $("#yjf").val()
					},
					async : false,
					cache : false,
					error : function(){
						
						alert('网络发生异常,请重试.....');
					},
					success	:	function(data){
						if(data == 'error'){
							
							alert('投注失败!');
						}else{
							alert('投注成功!');
							clearOtherTotalValue();
							$("#yues").text(data);
							getJrtzList();
						}
					}
				});
			}
		}
		
	});
	
	//	提交前设置隐藏值
	function setFormData(){
		
		var onemoney = ForDight(parseFloat($("#danbeizongjine").text())/parseInt($("#multiples").val()),2);
		var beishu = 0;
		var zhushu = 0;
		var codes = "";
		$.each($("#mainm_ml2r ul"),function(i,item){
			
			codes += $(item).find("li:nth-child(2)").text() + "$";
		});
		
		codes = codes.substring(0,codes.length - 1);
		$("#protype").val($("input[name='wflx']:checked").val());
		$("#codes").val(codes);
		$("#onemoney").val(onemoney);
		$("#allmoney").val($("#danbeizongjine").text());
		$("#beishu").val($("#multiples").val());
		
		if($("#btxishudhid .color").attr("yjfVal") == '1'){
			
			$("#yjf").val("0");
		}else if($("#btxishudhid .color").attr("yjfVal") == '0.1'){
			
			$("#yjf").val("1");
		}else if($("#btxishudhid .color").attr("yjfVal") == '0.01'){
			
			$("#yjf").val("2");
		}
		
	}
	
	//	追号
	$("#zhuihao_enter").bind("click", function(){
		
		if($("#nowTime").text() == "00:00:00"){
			
			alert('本期已过销售期,请等待下一期的投注!');
			
			return false;
		}
		
		//	设置Form的值
		setFormData();
		
		if($.trim($("#codes").val()) == ''){
			alert('请选择投注号码后再进行投注!');
			return false;
		}
		
		$.ajax({
			
			url : "/xinlu/hljssc/hljsscAction.html",
			type : "post",
			dataType : "json",
			data : {
				pageId : "hljssc",
				doAction : "getLottyList"
			},
			async : false,
			cache : false,
			error : function(){
				
				alert('网络发生异常,请重试.....');
			},
			success : function(data){
				
				var val = "";
				$.each(data, function(i, item){
					val += "<ul class='bg_yellow'>" + "<li class='liwidth1'> <input type='checkbox' name='qihaos' value='" + item.qh + "' />" + item.qh +"期</li>" +
								"<li class='liwidth'><input name='zhuiBeishu' id='zhbeishu_"+ i + "' maxlength='5' size='8' value='1' type='text' /></li>" +
								"<li class='liwidth'>￥<span id='zhuihaotouru_" + i + "'>" + $("#onemoney").val() + "</span></li>" +
								"<li class='liwidth'>￥<span id='leijitouru_" + i + "'>" + "0.00</span>" +
								"<li class='liwidth'></li>" +
								"<li class='liwidth'></li>" +
							"</ul>";
				});
				
				$("#zhuihaolist").html(val);
			}
			
		});
		
		//	追号期数选择
		$("#qiNum").bind("change", function(){
		
			var qiNum = parseInt($("#qiNum option:selected").val());
			
			$.each($("input[name='qihaos']"), function(i, item){
				
				$(item).attr("checked", false);
				
			});	
			
			$.each($("input[name='qihaos']"), function(i, item){
				if(qiNum - i >= 1){
					$(item).val();
					$(item).attr("checked", true);
				}else{
					return false;
				}
				
			});		
			
			if(qiNum == 0){
				
				$.each($("input[name='qihaos']"), function(i, item){
				
					$(this).attr("checked", false);
				});	
				
				$("#zhzje").val("0.00");
				$("#zhzqs").val("0");
			}
			
			var sumMoney = 0;
			var qishu = 0;
			$.each($("input[name='qihaos']:checked"), function(i,item){
				
				$(this).parent().next().find("span").text(ForDight(parseInt($(this).val()) * parseFloat($("#onemoney").val()), 2));
				
				sumMoney += ForDight(parseFloat($(this).parent().parent().find("li:nth-child(3) span").text()),2);
				
				$(this).parent().parent().find("li:nth-child(4) span").text(ForDight(sumMoney,2));
				qishu++;
			});
			
			if(qiNum > 0){
				
				$("#zhzje").text(ForDight(sumMoney, 2));
				$("#zhzqs").text(qishu);
			}
		});
		
		//	选中时候修改累计金额
		$("input[name='qihaos']").bind("click",function(){
			
			$(this).parent().parent().find("li:nth-child(4) span").text("0.00");
			
			var sumMoney = 0;
			var qishu = 0;
			$.each($("input[name='qihaos']:checked"), function(i,item){
				sumMoney += ForDight(parseFloat($(item).parent().parent().find("li:nth-child(3) span").text()),2) ;
				$(this).parent().parent().find("li:nth-child(4) span").text(ForDight(sumMoney,2));
				qishu++;
			});
			
			$("#zhzje").text(ForDight(sumMoney,2));
			$("#zhzqs").text(qishu);
		});
		
		//	倍数发生改变的时候,修改累计金额
		$("input[name='zhuiBeishu']").bind("change", function(){
			
			$(this).parent().next().find("span").text(ForDight(parseInt($(this).val()) * parseFloat($("#onemoney").val()),2));
			
			var sumMoney = 0;
			$.each($("input[name='qihaos']:checked"), function(i,item){
				
				sumMoney += ForDight(parseFloat($(this).parent().parent().find("li:nth-child(3) span").text()), 2);
				
				$(this).parent().parent().find("li:nth-child(4) span").text(sumMoney);
			});
			$("#zhzje").text(sumMoney);
		});
		
		$.blockUI({        
			message: $("#main_ml3"),
			css :{
				width : "432px",
				left : "51%",
				top : "25%"
			}
		});
 
        //	setTimeout($.unblockUI, 20000); 
		
	});
	
	
	$("#clbet").bind("click", function(){
		
		
		$.unblockUI();
		$("#zhuihaolist").html('');
		$("#zhzje").text("0.00");
		$("#zhzqs").text("0");
		$("#qiNum option:selected").attr("selected", false);
	});
	
	$("#multiples").bind("change", function(){
		
		var beishu = $("#multiples").val();
		
		//	$("#danbeizongzhushu").text(beishu);
		if($("#danbeizongzhushu").text()!='0'){
			
			$("#beishu").val(beishu);
			
			$("#allmoney").val(ForDight(parseInt(beishu) * parseFloat($("#danbeizongzhushu").text()) * parseFloat("2.00")  * parseFloat($("#btxishudhid .color").attr("yjfVal")),2));
			$("#danbeizongjine").text(ForDight(parseInt(beishu) * parseFloat($("#danbeizongzhushu").text()) * parseFloat("2.00")  * parseFloat($("#btxishudhid .color").attr("yjfVal")), 2));
		}
		
	});
	
	$("#yesbet").bind("click", function(){
		
		$("#expect").val($("#nowdatenumers").text());
		
		if($("input[name='zjhtz']").attr("checked") == 'checked'){
			
			$("#istop").val("1");
		}else{
			
			$("#istop").val("0");
		}
		
		var iszhuihao = false;
		var zhuihaoqishu = 0;
		var zhuihaoqihao = "";
		var zhuihaobeishu = "";
		var totalmoney = 0;
		$.each($("input[name='qihaos']:checked"),function(i, item){
			
			zhuihaoqishu = i + 1;
			zhuihaoqihao = zhuihaoqihao + $(item).val() + ",";
			zhuihaobeishu = zhuihaobeishu + $(item).parent().parent().find("input[name='zhuiBeishu']").val() + ",";
			
			totalmoney +=  ForDight(parseFloat($(item).parent().parent().find("li:nth-child(3) span").text()),2);
		});
		
		if(zhuihaoqishu == 0){
			
			alert('请选择追号的期数,从第一期开始!');
			return false;
		}
		
		if(!$("input[name='qihaos']:first(0)").attr("checked")){
			
			alert('追号的期数必须包含第一期开始!');
			return false;
		}
		
		$("#allmoney").val(totalmoney);
		$("#iszhuihao").val(zhuihaoqishu);
		$("#zhuihaoqihao").val(zhuihaoqihao.substr(0, zhuihaoqihao.length - 1));
		$("#zhuihaobeishu").val(zhuihaobeishu.substr(0,zhuihaobeishu.length - 1));
		$("#xl").val($("#shop_right select option:selected").val());
		$("#doAction").val("addTzjlInfo");
		$("#pageId").val("hljssc");
		
		if($("#btxishudhid .color").attr("yjfVal") == '1'){
			
			$("#yjf").val("0");
		}else if($("#btxishudhid .color").attr("yjfVal") == '0.1'){
			
			$("#yjf").val("1");
		}else if($("#btxishudhid .color").attr("yjfVal") == '0.01'){
			
			$("#yjf").val("2");
		}
		
		var message = "您确认要投注？\r\n";
//		var cods = $("#codes").val().split("$");
//		
//		for(var i = 0; i < cods.length; i++){
//			
//			message += cods[i] + "\r\n";
//		}
		
		if(zhuihaoqishu > 1){
			
			message += "追加" + zhuihaoqishu + "期？";
		}
		
		if(checkFormData()){
			if(confirm(message)){
				
				$.ajax({
					url : "/xinlu/hljssc/hljsscAction.html",
					type : "post",
					data : $("#tzForm").serialize(),
					async : false,
					cache : false,
					error : function(){
					
						alert('网络发生异常,请重试....');
					},
					success : function(data){
						
						if(data != 'error'){
							
							alert('追号成功!');
							clearOtherTotalValue();
							$("#clearOtherTotalValue").html('');
							$.unblockUI();
							$("#yues").text(data);
							getJrtzList();
						}else{
							
							alert('投注失败!');
						}
					}
				});
				
			}
		}
		
		
	});
	
	$("#jrkj").bind("click", function(){
		$("#jrkj").attr("class", "Slider01");
		$("#jrtz").attr("class", "Slider02");
		$("#nagvior1 tr:nth-child(2)").css("display", "none");
		$("#jrtzTable").css("display", "none");
		$("#nagvior1 tr:nth-child(1)").css("display", "");
		$("#zjxxTable").css("display", "");
	});
	
	$("#jrtz").bind("click", function(){
		$("#jrtz").attr("class", "Slider01");
		$("#jrkj").attr("class", "Slider02");
		$("#nagvior1 tr:nth-child(1)").css("display", "none");
		$("#zjxxTable").css("display", "none");
		$("#nagvior1 tr:nth-child(2)").css("display", "block");
		$("#jrtzTable").css("display", "block");
		
	});
	
});



function checkFormData(){
	
	if($("#mainm_ml2r ul").length == 0){
		
		alert('请选择投注号码!');
		
		return false;
	}
	
	var flag = false;
	
	$.ajax({
		url : "/xinlu/hljssc/hljsscAction.html",
		type : "post",
		data : {
			
			pageId : "hljssc",
			doAction : "checkAllMoney",
			allmoney : $("#allmoney").val()
		},
		async : false,
		cache : false,
		error : function(){
			
			alert('网络发生异常,请重试....');
		},
		success : function(data){
			
			if(data == 1){
				flag = true;
				alert('您的金额不够,请充值后,再2购买!');
			}else if(data == 2){
				
				flag = true;
				alert('请登录后再进行投注!');
			}
		}
	});	
	
	if(flag){
		
		return false;
	}
	
	return true;
}

　function ForDight(Dight,How){

　　var c=Math.pow(10,How);

　　return Math.round(Dight*c)/c;

　　}

//	注册开奖信息
function regKjxxLaster(){
	
	//	10秒获取开奖信息
	//	getKjxxLaster();
	getKjxxLaster();
	window.setInterval(getKjxxLaster,30000);
}

//	获取开奖信息
function getKjxxLaster(){
	$.ajax({
		
		url : requestUrl,
		type : "post",
		dataType : "json",
		data : {
			pageId : "hljssc",
			doAction : "getZjxxList"
		},
		async : false,
		cache : false,
		error : function(error){
			
			alert('网络发生异常,请重试....');
		},
		success : function(data){
			
			if(data != null && data != ''){
				
				$("#zjxxTable").html('');
				
				$.each(data,function(i, item){
					
					if(i == 0){
						$("#addtime").text(item.kjsj.substring(0, item.kjsj.length - 3));
						$("#lastIssue").text(item.qs.substring(8,11));
						$("#lastIssueNum").text(item.kjhm);
					}
					
					var tr = $("<tr></tr>").attr("class", "zjxxlistTr");
					
					$("<td>" + item.qs + "</td>").attr("class", "zjxxlistQh").attr("class", "zjxxlistQh").appendTo(tr);
					$("<td>" + item.kjhm + "</td>").attr("class", "zjxxlistKjhm").attr("class", "zjxxlistKjhm").appendTo(tr);
					$("<td>" + item.kjsj + "</td>").attr("class", "zjxxlistKjsj").attr("class", "zjxxlistKjsj").appendTo(tr);
					tr.appendTo("#zjxxTable");
				});
			}
		}
	});

}

	function checkDsInput(str, num){
		var par = /^([0-9]{3,3}(([; ,\t]){0,}))+$/;
		
		if(num == 2){
			
			par = /^([0-9]{2,2}(([; ,\t]){0,}))+$/;
		}
		
		return par.test(str);
	}

function getJrtzList(){
		
		$.ajax({
			
			url : requestUrl,
			type : "post",
			dataType : "json",
			data : {
				pageId : 'hljssc',
				doAction : 'getJrtzList'
			},
			error : function(){
				
				alert('网络发生异常，请重试...');
			},
			success : function(data){
				$("#jrtzTable").html('');
				if(data != null && typeof(data) != 'undefined' && data != ''){
					
					$.each(data,function(i, item){
						
						var tr = $("<tr></tr>").attr("class", "jrtzlistTr");
					
						$("<td>" + item.qh + "</td>").attr("class", "jrtzlistQh").appendTo(tr);
						$("<td>" + item.wflxjczwm + "</td>").attr("class", "jrtzlistWflx").appendTo(tr);
						$("<td>" + item.tzhm + "</td>").attr("class", "jrtzlistKjhm").appendTo(tr);
						$("<td>" + item.dgsj + "</td>").attr("class", "jrtzlistKjsj").appendTo(tr);
						tr.appendTo("#jrtzTable");
					});
				}
			}
		});
	}


